#include "../Field/Field1D.h"

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;


template<class Type>
Field1D<Type>::Field1D() : Field<Type>()
{
}

template<class Type>
Field1D<Type>::Field1D(vector<int> dims) : Field<Type>(dims)
{
    allocate_dims(dims);
}

template<class Type>
Field1D<Type>::Field1D(vector<int> dims, string name) : Field<Type>(dims, name)
{
    allocate_dims(dims);
}

template<class Type>
Field1D<Type>::~Field1D()
{
    if (this->data_!=NULL) {
        delete [] this->data_;
    }
}

template<class Type>
void Field1D<Type>::allocate_dims(std::vector<int> dims)
{
    this->dims_ = dims;
    if (dims.size()!=1) log_error<<"Alloc n dim must be 1 : " << dims.size();

    this->data_ = new Type[ this->dims_[0] ];

    for (int i=0; i<this->dims_[0]; i++) this->data_[i]=0.0;

    this->dims_global_ = this->dims_[0];

}

template<class Type>
Field1D<Type>& Field1D<Type>::operator=(const Field1D<Type>& field1D)
{
    if (this->dims_[0] != field1D.dims_[0])
    {
        log_error<<"dims not equal";
    }
    for(int i = 0; i < this->dims_global_; i++)
    {
        this->data_[i] = field1D.data_[i];
    }

    return *this;
}


template class Field1D<double>;
template class Field1D<int>;

